package com.heima.article.controller;

import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.common.dtos.ArticleHomeDto;
import com.heima.model.common.dtos.ArticleInfoDto;
import com.heima.model.common.dtos.CollectionBehaviorDto;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 陈辉
 * @data 2024 9:51
 */
@RestController
@Slf4j
@RequestMapping("/api/v1/")
public class ApArticleController {

    @Autowired
    private ApArticleService apArticleService;

    /**
     * 加载首页
     *
     * @return
     */
    @PostMapping("/article/load")
    public ResponseResult load(@RequestBody ArticleHomeDto homeDto){
        return apArticleService.loadHotArticle(homeDto, ArticleConstants.LOADTYPE_LOAD_INDEX);
    }

    /**
     * 加载更多
     *
     * @return
     */
    @PostMapping("/article/loadmore")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto homeDto){
        return apArticleService.load(homeDto,ArticleConstants.LOADTYPE_LOAD_MORE);
    }

    /**
     * 加载更新
     *
     * @return
     */
    @PostMapping("/article/loadnew")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto homeDto){
        return apArticleService.load(homeDto,ArticleConstants.LOADTYPE_LOAD_NEW);
    }

    /**
     * 用户收藏文章
     *
     * @param behaviorDto
     * @return
     */
    @PostMapping("/collection_behavior")
    public ResponseResult collectionBehavior(@RequestBody CollectionBehaviorDto behaviorDto, @RequestHeader("userId") String userId){
        log.info("用户收藏文章：{},用户id为：{}",behaviorDto,userId);
        return apArticleService.collectionBehavior(behaviorDto,userId);
    }

    /**
     * 加载文章行为-数据回显
     *
     * @param infoDto
     * @param userId
     * @return
     */
    @PostMapping("/article/load_article_behavior")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleInfoDto infoDto, @RequestHeader("userId") String userId){
        log.info("加载文章行为-数据回显：{},用户id：{}",infoDto,userId);
        return apArticleService.loadArticleBehavior(infoDto,userId);
    }
}
